{% extends "base/base.html" %}

{% comment %}

 Copyright 2013 - Tom Alessi

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and 
 limitations under the License.

{% endcomment %}


{% block content %}

<script type="text/javascript">

   // Update Slider
   $(function() {
      $("#update_link").click(function () {
        $("#update").slideToggle("slow");
      });
    });
</script>

<div class="row">
  <div class="large-4 columns">
  	<span class="navigation">
	  <a href="/webmaster/messages">Messages List</a> 
	  |
	  <a href=# id="update_link">Update Message</a>
	</span>
	<br><br><br>
  </div>
</div>

<div class="row">
  <div class="large-12 columns">
  	<b>Subject:</b> {{detail.0.subject}}
	<br><br>
  </div>
</div>

<div class="row">
  <div class="large-12 columns">
  	<b>Assigned to:</b> {% if detail.0.assignee__first_name and detail.0.assignee__last_name %}{{detail.0.assignee__first_name}} {{detail.0.assignee__last_name}}{% else %}UNASSIGNED{% endif %}
	<br><br>
  </div>
</div>

<div class="row">
  <div class="large-11 columns">
  	{# If there are form errors, remove the display: none #}
  	<div id="update" {% if not form.errors %}style="display: none;"{% endif %}>
  	  <form method="POST" name="message_detail" action="/webmaster/message_update">
	  {% csrf_token %}
        <fieldset>
  	      <legend>Add Update</legend>
	      <textarea class="small{% if form.errors %} error{% endif %}" name="update" placeholder="Enter an update"></textarea>
	      {% if form.update.errors %}
	      <small class="error">
	        {% for error in form.update.errors %}{{error}}{% endfor %}
	      </small>
    	  {% endif %}
    	  <br>
    	  <label>Status:
	        <select name="status" class="status">
	       	  <option value="" selected="true">--</option>
	          {% for status in statuses %}
	            {% if status.status == detail.0.status__status %}
	              <option value="{{status.id}}" selected="true">{{status.status}}</option>
	            {% else %}
	              <option value="{{status.id}}" >{{status.status}}</option>
	            {% endif %}
		      {% endfor %}
	        </select>
      	  </label>
    	  <label>Assignee:
	        <select name="assignee" class="assignee">
	       	  <option value="" selected="true">--</option>
	          {% for user in users %}
	            {% if user.id == detail.0.assignee__id %}
	              <option value="{{user.id}}" selected="true">{{user.first_name}} {{user.last_name}}</option>
	            {% else %}
	              <option value="{{user.id}}">{{user.first_name}} {{user.last_name}}</option>
	            {% endif %}
		      {% endfor %}
	        </select>
      	  </label>
          {% if form.status.errors %}
          <small class="error">
          {% for error in form.status.errors %}{{error}}{% endfor %}
          </small>
          {% endif %}

    	  <br><br>
    	  <input type="hidden" name="id" value="{{id}}">
	      <input type="submit" class="small button" value="submit"/>
	    </fieldset>
	    <br><br>
	  </form>
    </div>
  </div>
</div>

<div class="row">
  <div class="large-12 columns">
   	<table>
	  <tr>
	  	<th>WEBMASTER MESSAGE (status:{{detail.0.status__status}})</th>
	  </tr>
	  <tr>
		<td>
          {{detail.0.body|safe}}
		</td>
	  </tr>
	</table>
  </div>
</div>

<div class="row">
  <div class="spacer_small"></div>
</div>

{% if updates %}
<div class="row">
  <div class="large-12 columns">
	<table>
	  <tr>
	  	<th colspan="3">UPDATES</th>
	  </tr>
	  <tr>
		<th>Date</th>
		<th>User</th>
		<th>Update</th>
	  </tr>

	  {% for update in updates %}
	  <tr>
		<td>{{update.date|date:"Y-m-d H:i:s"}}</td>
		<td>{{update.user_id__first_name}} {{update.user_id__last_name}}</td>
		<td>{{update.update}}</td>
	  </tr>
	  {% endfor %}
	</table>
  </div>
</div>
{% else %}
NO UPDATES
{% endif %}

<div class="row">
  <div class="spacer_small"></div>
</div>

{% endblock %}
